import { param2Obj } from '../util/urlUtil'
import Mock from 'mockjs'
var List = []
for (var i = 0; i < 100; i++) {
    List.push({
        id: Mock.mock('@increment(1)'),
        card: Mock.mock('@zip()'),
        type: "普通会员",
        level: "VIP" + Mock.mock('@integer(1, 3)'),
        name: Mock.mock('@cname'),
        phone: Mock.mock(/^[1][3-9][0-9]{9}$/),
        consumption: Mock.mock(('@integer(1000, 100000)')),
        balance: Mock.mock(('@integer(10000, 100000)')),
        stockpile: Mock.mock(('@integer(10000, 100000)')),
        integral: Mock.mock(('@integer(100, 10000)')),
        date: Mock.mock('@datetime()'),
        time: Mock.mock('@datetime()'),
        state: true
    })
}
export default {
    //搜索,翻页
    getVipData: config => {
        console.log('config', param2Obj(config.url));
        var { page, pageSize ,keyword,viptype} = param2Obj(config.url)
        var res = List.filter(item => {
            return item.name.indexOf(keyword) != -1;
        })
        if(viptype != '')
        {
            res = res.filter(item => {
                return item.level == viptype;
            })
        }
        // console.log("page:",page)
        var resLimit = res.filter((item, index) => {
            return (page - 1) * pageSize <= index && index < page * pageSize
        })
        return {
            code: 200,
            msg: '请求成功',
            data: resLimit
        }
    },
    //删除
    getDeletData: config => {
        var { id } = JSON.parse(config.body)
        var res = List.filter(item => item.id != id)
        List = res
        return {
            code: 200,
            msg: '删除成功',
            data: null
        }
    }



    // getHomeData:config=>{
    //     console.log("Co nfig:",param2Obj(config.url));
    //     var {page,pageSize} = param2Obj(config.url)
    //     var resLimit = res.filter((item,index)=>{
    //         return(page-1) * pageSize <= index    &&  index < page * pageSize
    //     })
    //     return{
    //         code:200,
    //         msg:'请求成功',
    //         data:resLimit,
    //         total:List.length 
    //     }
    // },
}
